package oss.ngocminh.fw.forum;

import java.io.IOException;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

import org.apache.http.client.HttpClient;

import oss.ngocminh.fw.data.Post;
import oss.ngocminh.fw.data.Thread;

/**
 * Interact with a real forum such as lamchame.com.
 * @author cumeo89
 *
 */
public interface ForumAdapter {

	/**
	 * Get the HTTP client this adapter uses to connect to forum.
	 * To change or use forum user credential e.g. login using OpenID/FBConnect.
	 * @return
	 */
	HttpClient getHttpClient();
	
	/**
	 * Login using a pair of user name and password.
	 * @param userName
	 * @param password
	 * @return
	 * @throws IOException 
	 */
	boolean login(String userName, String password, String baseUrl) throws IOException;
	
	/**
	 * Get all posts in a page.
	 * @param thread
	 * @param page
	 * @return
	 * @throws IOException 
	 * @throws ParseException 
	 */
	List<Post> getPostsOfPage(Thread thread, int page) throws IOException, ParseException;

	void getPostsOfPage(Thread thread, int page, PostLoadingCallback callback) throws IOException, ParseException;
	
	/**
	 * Get all posts from the specified page to the last page
	 * @param thread
	 * @param page
	 * @return
	 * @throws IOException
	 * @throws ParseException
	 */
	List<Post> getPostsFromPage(Thread thread, int page) throws IOException, ParseException;
	
	void getPostsFromPage(Thread thread, int page, PostLoadingCallback callback) throws IOException, ParseException;
	
	/**
	 * Get posts from <code>fromDate</code> to now. 
	 * @param thread TODO
	 * @param from
	 * @return
	 */
	List<Post> getNewPosts(Thread thread, Date fromDate) throws IOException, ParseException;
	
	void getNewPosts(Thread thread, Date fromDate, PostLoadingCallback callback) throws IOException, ParseException;
	
	/**
	 * Get all posts of the specified forum. 
	 * @param thread TODO
	 * @return
	 * @throws ParseException 
	 * @throws IOException 
	 */
	List<Post> getAllPosts(Thread thread) throws IOException, ParseException;
	
	void getAllPosts(Thread thread, PostLoadingCallback callback) throws IOException, ParseException;
	
	/**
	 * Submit a new post using current credential (see {@link #login(String, String)}.
	 * @param post
	 * @param thread TODO
	 * @return
	 */
	boolean submitPost(Post post, Thread thread);
	
}
